/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.dc.actor;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.actor.UntypedActorFactory;
import akka.routing.RoundRobinPool;
import akka.routing.RoundRobinRouter;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Administrator
 */
public class ActorManager {
    
    private static ActorManager actorManager;
    private Map<String, ActorRef> actors = new HashMap<String, ActorRef>();
    
    private ActorSystem system = ActorSystem.create("myActor");
    
    public static ActorManager getIntance() {
        if (actorManager == null) {
            actorManager = new ActorManager();
            
        }
        
        return actorManager;
    }
    
    public void initActor() {
        
        ActorRef sendCacheServerActor = system.actorOf(Props.create(SendCacheServerActor.class), "SendCacheServerActor");
        
        ActorRef upzipActor = system.actorOf(
                new RoundRobinPool(6).props(Props.create(UnzipActor.class)), "upzipActor");
        
        actors.put("SendCacheServerActor", sendCacheServerActor);
        actors.put("upzipActor", upzipActor);
    }
    
    public ActorRef getActor(String actorName) {
        return actors.get(actorName);
    }
    
    public void destory() {
        for (String key : actors.keySet()) {
            
        }
        System.out.println("关闭akka");
        system.shutdown();
        
    }
    
}
